package com.artpri.interceptor;

import java.util.Map;

import com.artpri.action.user.LoginAction;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

public class LoginInterceptor extends AbstractInterceptor {

	private static final long serialVersionUID = -6853509832364477312L;

	@Override
	public String intercept(ActionInvocation invocation) throws Exception {
		
		System.out.println("执行LoginInterceptor!!!");
		
		if (LoginAction.class == invocation.getAction().getClass() ) {
			return invocation.invoke();
		}
		
		Map<String, Object> map = invocation.getInvocationContext().getSession();
		
		if (null == map.get("user")) {
			return Action.LOGIN;
		}
		
		return invocation.invoke();
	}

}
